package com.ebus.test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ebus.vo.BusLine;

public class Object2Json {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//getObjectValue();
		List<HashMap<String, String>> mapList = getMap();
		//System.out.println(JSONObject.fromObject(map).toString());
		System.out.println(JSONArray.fromObject(mapList));
	}

	private static void getObjectValue() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		List<BusLine> list = new ArrayList<BusLine>();
		for (int i = 1; i < 10; i++) {
			BusLine busline = new BusLine();
			busline.setBusNumber("" + i);
			busline.setBusLine("1=月亮湾,2=荔湾路西,3=南山花园,4=深大附中,5=青青世界,6=前海沿湖路口");
			busline.setBusRunType(true);
			list.add(busline);
		}

		JSONArray jsonArray = JSONArray.fromObject(list);
		System.out.println(jsonArray);
	}
	
	private static List<HashMap<String, String>> getMap() {
		List<HashMap<String, String>> mapList = new ArrayList<HashMap<String,String>>();
		
		HashMap<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("BUS_NUMBER", "49");
		paramMap.put("BUS_LINE", "1=月亮湾,2=荔湾路西,3=南山花园,4=深大附中,5=青青世界,6=前海沿湖路口,7=太子山庄,8=信诺公司,9=南山村西,10=鼎太风华,11=南头火车西站,12=阳光棕榈园,13=大新村");
		paramMap.put("BUS_END_TIME", "20:30:00");
		paramMap.put("BUS_RUN_TYPE", "false");
		paramMap.put("BUS_START_TIME", "21:05:08");
		
		HashMap<String, String> paramMap1 = new HashMap<String, String>();
		paramMap1.put("BUS_NUMBER", "49");
		paramMap1.put("BUS_LINE", "4=深大附中,5=青青世界,6=前海沿湖路口,7=太子山庄,8=信诺公司,9=南山村西,10=鼎太风华,11=南头火车西站,12=阳光棕榈园,13=大新村");
		paramMap1.put("BUS_END_TIME", "21:00:00");
		paramMap1.put("BUS_RUN_TYPE", "true");
		paramMap1.put("BUS_START_TIME", "21:05:08");
		
		mapList.add(paramMap);
		mapList.add(paramMap1);
		
		System.out.println(mapList);
		return mapList;
	}

}
